package com.tanhua.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.HashMap;
import java.util.Map;


public class JwtUtil {
    // 创建token
    public static String createToken(Object mobile,Long id,String secret) {
        Map<String, Object> claims = new HashMap<String, Object>();
        claims.put("mobile", mobile);
        claims.put("id", id);
        return Jwts.builder()
                .setClaims(claims) //设置响应数据体
                .signWith(SignatureAlgorithm.HS256, secret) //设置加密方法和加密盐
                .compact();
    }


    //测试
/*    public static void main(String[] args) {

        //参数1：用户的任意数据
        //参数2：用户的id
        //参数3：盐
        //123456--->fgsfhsddfgjsdfgd
        //12345 130211011111@qq.com---->fsfdgfhhjjhgfdsfdghghgfdssasdfgghgfd
        String token=createToken("123456",1l,"tanhua");
        System.out.println(token);//eyJhbGciOiJIUzI1NiJ9.eyJtb2JpbGUiOiIxMjM0NTYiLCJpZCI6MX0.eZTR1y-FAmd6RRweAz0sVHK5uZD9WExcKETLxWuN6SU
    }*/

}